package com.dawnClass.controller;

import com.dawnClass.service.CourseESService;
import com.dawnClass.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;
import java.util.Map;

//请求编写
@RestController
public class CourseESController {
    @Autowired
    private CourseESService courseESService;
    @Autowired
    private CourseService courseService;

    @GetMapping("/parse/{keyword}")
    public Boolean parse(@PathVariable("keyword") String keyword) throws IOException {
        return courseESService.parseContent(keyword);
    }
    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    public ModelAndView search(@PathVariable("keyword") String keyword,
                               @PathVariable("pageNo") int pageNo,
                               @PathVariable("pageSize") int pageSize) throws IOException{
        ModelAndView mav = new ModelAndView();
        List<Map<String, Object>> searchPage = courseESService.searchPage(keyword, pageNo, pageSize);
        mav.addObject("searchPage",searchPage);
        mav.setViewName("course/course");
        return mav;
    }

}
